package com.imooc.controller;

import com.imooc.service.impl.StuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//@Controller
@ApiIgnore  // Swagger2的显示中忽略该 Controller
@RestController
public class HelloController {

    @Autowired
    private StuServiceImpl stuServiceImp;

    @GetMapping("/hello")
    public Object hello(){
        stuServiceImp.saveChild1();
        return "hello world";
    }

    /**
     * 通过HttpServletRequest 可以获取到SrpingSession
     * @param request
     * @return
     */
    @GetMapping("/setSession")
    public Object setSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("userInfo", "new user");
        session.setMaxInactiveInterval(3600);
        session.getAttribute("userInfo");
//        session.removeAttribute("userInfo");
        return "ok";
    }
}
